﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WITM.DAL
{
    public class SpendingItemRepository : ISpendingItemRepository
    {
        private WhereIsTheMoneyDBEntities context;

        public SpendingItemRepository(WhereIsTheMoneyDBEntities dbcontext)
        {
            context = dbcontext;
        }

        #region ISpendingItemRepository Members

        public IEnumerable<SpendingItems> GetAll()
        {
            return context.SpendingItems.ToList();
        }

        public IEnumerable<SpendingItems> Find(System.Linq.Expressions.Expression<Func<SpendingItems, bool>> where)
        {
            return Find(where, false);
        }

        public IEnumerable<SpendingItems> Find(System.Linq.Expressions.Expression<Func<SpendingItems, bool>> where, bool fullPath)
        {
            if (fullPath)
            {
                return context.SpendingItems.Include("SpendingCategories.Users").Where(where).ToList();
            }
            else
            {
                return context.SpendingItems.Where(where).ToList();
            }
        }

        public SpendingItems First(System.Linq.Expressions.Expression<Func<SpendingItems, bool>> where)
        {
            return context.SpendingItems.FirstOrDefault(where);
        }

        public void Add(SpendingItems item)
        {
            context.AddToSpendingItems(item);
        }

        public void Delete(SpendingItems item)
        {
            throw new NotImplementedException();
        }

        public void Attach(SpendingItems item)
        {
            context.Attach(item);
        }

        #endregion

        #region ISpendingItemRepository Members



        #endregion
    }
}
